<?php
$id = $_GET['id'] ?? 'HeChengChaXiu.jar';

$jarurls = [
    'http://192.168.2.111:5244/d/ty1/hccx/' . $id,
    'http://192.168.2.111:5244/d/yd//hccx/' . $id
];

shuffle($jarurls); 

$success = false;

foreach ($jarurls as $url) {
    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true
    ]);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($httpCode === 302) {
        $redirectUrl = str_replace('192.168.2.111', 'rihou.tpddns.cn', $url);
        header("Location: $redirectUrl");
        $success = true;
        break;
    }

    curl_close($ch);
}

if (!$success) {
     header("Location:  http://rihou.tpddns.cn:88/hccx/$id");
}
// Add visit record
$file = '../访问记录.txt';
$ua = $_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER['REMOTE_ADDR'];
$time = date('Y-m-d H:i:s');

$data = "UA: $ua | IP: $ip | 站点: $id \n";

file_put_contents($file, $data, FILE_APPEND);
?>